var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
script.setAttribute("src", "js/general_functions.js");
document.getElementsByTagName("head")[0].appendChild(script);

includeJS("js/jscharts.js");


function load(page, type, maTS){
    draw_chart();
    view_dsbaithi();
    // type = 0 : thí sinh
    // type = 1 : quản trị
    document.getElementById("dsbaithi").innerHTML = "<p align='center'>Đang tải danh sách bài thi ...</p>";
    xmlhttp = createXMLHttpRequest();
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            document.getElementById("dsbaithi").innerHTML = xmlhttp.responseText;
        }
    }
    var serverURL = "gui_handling/thongke_load.jsp?page=" + page + "&type=" + type + "&mats=" + maTS + "&t=" + (new Date()).getTime();
    xmlhttp.open("GET",serverURL,true);
    xmlhttp.send();
}

function view_dsbaithi(){
//    document.getElementById("graph-region").style.display = "none";
//    document.getElementById("draw_chart_button").style.display = "block";
    document.getElementById("dsbaithi-region").style.display = "block";
    document.getElementById("view_dsbaithi_button").style.display = "none";
}

function draw_chart(){
    //document.getElementById("dsbaithi").innerHTML = "<p align='center'>Đang tải danh sách bài thi ...</p>";
    xmlhttp = createXMLHttpRequest();
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            var jsonFile = xmlhttp.responseText;
            var myChart = new JSChart('graph-region', 'line');
            myChart.setDataJSON("files/data.json");
            myChart.draw();
        }
    }
    var serverURL = "gui_handling/draw_chart.jsp?t=" + (new Date()).getTime();
    xmlhttp.open("GET",serverURL,true);
    xmlhttp.send();
    
    
    document.getElementById("graph-region").style.display = "block";
    document.getElementById("draw_chart_button").style.display = "none";
    document.getElementById("dsbaithi-region").style.display = "none";
    document.getElementById("view_dsbaithi_button").style.display = "block";
    
//    var myChart = new JSChart('graph-region', 'line');
//    myChart.setDataArray([[1, 5],[2, 6],[3, 5.7],[4, 6.5],[5, 10]], 'blue');
//    myChart.setDataArray([[1, 8],[2, 5.5],[3, 8.0],[4, 7.5],[5, 4.0]], 'green');
//    myChart.setDataArray([[1, 6.0],[2, 2.5],[3, 4.7],[4, 8.0],[5, 7.0]], 'gray');
//    myChart.setAxisPaddingBottom(40);
//    myChart.setTextPaddingBottom(10);
//    myChart.setAxisValuesNumberY(5);
//    myChart.setIntervalStartY(0);
//    myChart.setIntervalEndY(10);
//    myChart.setLabelX([2,'1']);
//    myChart.setLabelX([4,'2']);
//    myChart.setLabelX([6,'3']);
//    myChart.setLabelX([8,'4']);
//    myChart.setLabelX([10,'5']);
//    myChart.setAxisValuesNumberX(5);
//    myChart.setShowXValues(true);
//    myChart.setTitleColor('#454545');
//    myChart.setAxisValuesColor('#454545');
//    myChart.setLineColor('#A4D314', 'green');
//    myChart.setLineColor('#BBBBBB', 'gray');
//    myChart.setFlagColor('#9D16FC');
//    myChart.setFlagRadius(4);
//    myChart.setBackgroundImage('chart_bg.jpg');
//    myChart.setSize(616, 321);
//    myChart.draw();
}